package active;


import UserDao.UserDao;
import UserDao.UserDaoImpl.UserDaoImpl;
import com.google.gson.Gson;
import entity.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/login.do")
public class Login extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        //response.setContentType("text/html;charset=" + this.encoding);
        resp.setCharacterEncoding("UTF-8");

        String userid = req.getParameter("userid");
        String userpass = req.getParameter("userpass");
        UserDao dao=new UserDaoImpl();
        User user = dao.loginUser(userid, userpass);
        System.out.println(userid);
        System.out.println(userpass);
        PrintWriter out = resp.getWriter();

        if(user!=null){
            System.out.println("a");
            out.print("登录成功");

        }else{
            System.out.println("b");
            out.print("帐号或者密码错误!");
        }
        out.flush();
        out.close();
    }
}
